package com.renwei.yunlong.activity.contacts;

import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.base.BaseActivity;
import com.renwei.yunlong.utils.CommonUtils;
import com.zyf.fwms.commonlibrary.utils.StatusBarUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 证书名称--页面
 * <p>
 * Created by Administrator on 2017/8/23.
 */

public class CompanyCertificateNameActivity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "CompanyCertificateNameActivity";

    String action;
    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.et_phone)
    EditText etPhone;
    String certificateType="";

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_company_certificate_name);
        ButterKnife.bind(this);
        StatusBarUtil.setColor(this, CommonUtils.getColor(this, R.color.title_color), 0);
        certificateType=getIntent().getStringExtra("certificateType")==null?"32":getIntent().getStringExtra("certificateType");
        initData();
    }

    private void initData() {
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText("保存");
        ivBack.setVisibility(View.VISIBLE);
        ivBack.setOnClickListener(this);
        tvRight.setOnClickListener(this);
        Intent intent = getIntent();
        action = getIntent().getAction();
        etPhone.setInputType(InputType.TYPE_CLASS_TEXT);
        if ("1".equals(action)) {
            if ("32".equals(certificateType)) {
                tvTitle.setText("资质证书");
            } else {
                tvTitle.setText("证书");
            }
            String name = intent.getStringExtra("name") == null ? "" : intent.getStringExtra("name");
            if (name != null && name.length() > 0) {
                etPhone.setSelection(name.length() - 1);
            }
            etPhone.setText(name);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_right:
                if ("1".equals(action)) {
                    setResult(1, new Intent().putExtra("name", etPhone.getText().toString()));
                } else {
                    setResult(2, new Intent().putExtra("level", etPhone.getText().toString()));
                }
                finish();
                break;
            default:
                break;
        }
    }
}
